home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / pctjmr86.arc / DOS4AH.ASM next >
Assembly Source File  |  1985-12-16  |  3KB  |  60 lines

  1. code         segment
  2.              assume       cs:code
  3. ;  FUNCTION called from Turbo Pascal, which releases
  4. ;  PP_TO_RELEASE paragraphs of memory from the current
  5. ;  memory block using the DOS function 4AH. If this is
  6. ;  possible, then the Turbo stack is relocated to the high
  7. ;  end of the new allocation and function result is zero.
  8. ;  Otherwise the DOS error code is returned.
  9.  
  10. ; Pascal declaration:  
  11. ; FUNCTION DOS4AH(PP_TO_RELEASE:INTEGER):INTEGER;
  12.  
  13. arguments     struc                    ; Template to arguments.
  14. save_bp       dw       ?               ; Saved BP register.
  15. ret_adr       dw       ?               ; Return address (near call).
  16. ;-------------------------------------------------------------------
  17. pp_to_release dw       ?               ; INTEGER # of paragraphs 
  18.                                        ; to release.
  19. ;-------------------------------------------------------------------
  20. arguments     ends
  21.  
  22. dos4AH        proc      near
  23.               push      bp
  24.               mov       bp,sp          ; Establish access to arguments
  25.               push      ds             ; Save Turbo's data segment.
  26.  
  27.               mov       ax,cs          ; Calculate the paragraph size
  28.               mov       bx,ss          ; of the current block as 
  29.               add       bx,1000H       ; SS+1000H minus code segment
  30.               sub       bx,ax          ; address. Then calculate new 
  31.                                        ; size for memory block.
  32.               sub       bx,[bp].pp_to_release
  33.               mov       es,ax          ; Segment address of current 
  34.               mov       ah,4ah         ; memory block.
  35.               int       21h            ; Ask DOS to deallocate the space.
  36.               mov       ah,0
  37.               jc        exit           ; Was it possible to release
  38.                                        ; the memory?
  39.               mov       ax,ss          ; Yes: set up to relocate stack
  40.               mov       ds,ax          ; DS:SI is pointer to old stack
  41.               sub       ax,[bp].pp_to_release
  42.               mov       es,ax          ; ES:DI is the pointer to 
  43.               mov       bx,sp          ; the new stack.
  44.               mov       di,bx
  45.               mov       si,bx
  46.  
  47.               mov       cx,sp          ; Two's complement of SP 
  48.               neg       cx             ; is stack size.
  49.               cld                      ; Move cx bytes from 
  50.               rep       movsb          ; DS:SI to ES:DI ...
  51.                                        ; starting with the lowest byte
  52.               mov       ss,ax          ; Change the SS register ...
  53.               xor       ax,ax          ; and set the error code to 0.
  54. exit:         pop       ds
  55.               pop       bp
  56.               ret       4              ; Pop argument and 
  57. dos4AH        endp                     ; "function result".
  58. code          ends
  59.               end
  60.